/**
 * @author roua_troua
 */
package q10.GUI;

import q10.ArboriFunctionali;
import q10.Visitor.*;

public class DerivareCalculField implements Command {
    private ArboriFunctionali a;
    private javax.swing.JTextField textDerivareCalcul;
    private ArboriFunctionali stareA;
    private String stareText;

    public DerivareCalculField(ArboriFunctionali a,javax.swing.JTextField tdc){
        this.a = a;
        this.textDerivareCalcul = tdc;
    }

    public ArboriFunctionali execute(){
        getStare();
        Visitor derivVisitor = new DerivareCalculVisitor();
        a.acceptVisitor(derivVisitor);
        textDerivareCalcul.setText(Double.toString(((DerivareCalculVisitor)derivVisitor).getCalcul()));
        return a;
    }

    public ArboriFunctionali unexecute(){
        this.a = stareA;
        textDerivareCalcul.setText(stareText);
        return a;
    }
    
    public void getStare(){
        this.stareA = a;
        this.stareText = textDerivareCalcul.getText();
    }

    public void update(ArboriFunctionali af){
        this.a = af;
    }

}
